home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kcharsets.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.4 KB  |  143 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef KCHARSETS_H
  20. #define KCHARSETS_H
  21.  
  22. #include <qstring.h>
  23. #include <qfont.h>
  24. #include <qstringlist.h>
  25. #include <qptrlist.h>
  26. #include "kdelibs_export.h"
  27.  
  28. class KGlobal;
  29. class KCharsetsPrivate;
  30.  
  31. class QTextCodec;
  32.  
  33. /**
  34.  * Charset font and encoder/decoder handling.
  35.  *
  36.  * This is needed, because Qt's font matching algorithm gives the font
  37.  * family a higher priority than the charset.  For many applications
  38.  * this is not acceptable, since it can totally obscure the output,
  39.  * in languages which use non iso-8859-1 charsets.
  40.  *
  41.  * @author Lars Knoll <knoll@kde.org>
  42.  */
  43. class KDECORE_EXPORT KCharsets
  44. {
  45.     friend class KGlobal;
  46.  
  47. protected:
  48.     /** Protected constructor. If you need the kcharsets object, use
  49.  KGlobal::charsets() instead.
  50.     */
  51.     KCharsets();
  52.  
  53. public:
  54.  
  55.     /**
  56.      * Destructor.
  57.      */
  58.     virtual ~KCharsets();
  59.  
  60.     /**
  61.      * Provided for compatibility.
  62.      * @param name the name of the codec
  63.      * @return the QTextCodec. If the desired codec could not be found,
  64.      *         it returns a default (Latin-1) codec
  65.      */
  66.     QTextCodec *codecForName(const QString &name) const;
  67.  
  68.     /**
  69.      * Tries to find a QTextCodec to convert the given encoding from and to
  70.      * Unicode. If no codec could be found the latin1 codec will be returned an
  71.      * @p ok will be set to false.
  72.      * @return the QTextCodec. If the desired codec could not be found,
  73.      *         it returns a default (Latin-1) codec
  74.      */
  75.     QTextCodec *codecForName(const QString &n, bool &ok) const;
  76.  
  77.     /**
  78.      * Converts an entity to a character. The string must contain only the
  79.      * entity without the trailing ';'.
  80.      * @param str the entity
  81.      * @return QChar::null if the entity could not be decoded.
  82.      */
  83.     static QChar fromEntity(const QString &str);
  84.     /**
  85.      * Overloaded member function. Tries to find an entity in the
  86.      * QString str.
  87.      * @param str the string containing entified
  88.      * @param len is a return value, that gives the length of the decoded
  89.      * entity.
  90.      * @return a decoded entity if one could be found, QChar::null
  91.      * otherwise
  92.      */
  93.     static QChar fromEntity(const QString &str, int &len);
  94.  
  95.     /**
  96.      * Converts a QChar to an entity. The returned string does already
  97.      * contain the leading '&' and the trailing ';'.
  98.      * @param ch the char to convert
  99.      * @return the entity
  100.      */
  101.     static QString toEntity(const QChar &ch);
  102.  
  103.     /**
  104.      * Scans the given string for entities (like &amp;) and resolves them
  105.      * using fromEntity.
  106.      * @param text the string containing the entities
  107.      * @return the clean string
  108.      * @since 3.1
  109.      */
  110.     static QString resolveEntities( const QString &text );
  111.  
  112.     /**
  113.      * Lists all available encodings as names.
  114.      * @return the list of all encodings
  115.      */
  116.     QStringList availableEncodingNames();
  117.  
  118.     /**
  119.      * Lists the available encoding names together with a more descriptive language.
  120.      * @return the list of descriptive encoding names
  121.      */
  122.     QStringList descriptiveEncodingNames();
  123.  
  124.     /**
  125.      * Returns the language the encoding is used for.
  126.      * @param encoding the encoding for the language
  127.      * @return the language of the encoding
  128.      */
  129.     QString languageForEncoding( const QString &encoding );
  130.  
  131.     /**
  132.      * Returns the encoding for a string obtained with descriptiveEncodingNames().
  133.      * @param descriptiveName the descriptive name for the encoding
  134.      * @return the name of the encoding
  135.      */
  136.     QString encodingForName( const QString &descriptiveName );
  137.  
  138. private:
  139.     KCharsetsPrivate *d;
  140. };
  141.  
  142. #endif
  143.